package com.lovo;

import javax.swing.*;
import java.awt.*;

public class Test01 extends JFrame {
    private Image titleImg = Util.getImage("/images/vscode.png");
    private Image bgImg = Util.getImage("/images/timg.jpg");
    private Icon logoImg = Util.getIcon("/images/logo_small.png");
    private Icon btnImg = Util.getIcon("/images/btn.png");

    public Test01(){
        this.setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImg,0,0,800,600,this);
            }
        });
        // 设置空布局
        this.setLayout(null);

        JButton btn1 = new JButton("按钮1");
        btn1.setBounds(10,10,100,20);
        this.add(btn1);

        // 标签组件
        JLabel label1 = new JLabel("用户名：");
        label1.setBounds(10,40,80,50);
        label1.setForeground(Color.RED);
        label1.setFont(new Font("宋体",Font.PLAIN,30));
        this.add(label1);

        // 单行文本框
        JTextField textField1 = new JTextField();
        textField1.setBounds(70,40,100,20);
        this.add(textField1);

        // 密码框
        JPasswordField passwordField1 = new JPasswordField();
        passwordField1.setBounds(10,70,100,20);
        this.add(passwordField1);

        // 多行文本框
        JTextArea textArea1 = new JTextArea();
        // 带滚动条的容器
        JScrollPane scrollPane = new JScrollPane(textArea1);
        scrollPane.setBounds(10,100,100,200);
        this.add(scrollPane);

        JLabel imageLable = new JLabel(logoImg);
        imageLable.setBounds(120,10,108,108);
        this.add(imageLable);

        JButton imageBtn = new JButton(btnImg);
        imageBtn.setBounds(10,310,238,128);
        this.add(imageBtn);

        // 设置窗口大小
        this.setSize(800,600);
        this.setIconImage(titleImg);
        // 设置窗体的标题文字
        this.setTitle("测试窗口");
        // 设置窗体居中
        this.setLocationRelativeTo(null);
        // 设置窗口关闭时程序结束
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        // 设置窗体可见
        this.setVisible(true);

    }

    public static void main(String[] args) {
        new Test01();
    }
}
